<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Category_term_model extends Term_m
{
	private $array_slug = array();
	private $file_cache = 'mcache/category_term.php';
	
	function get_menu_slug_array($parent = 0,$pre_fix = '', $type = '' )
	{
		return parent::get_menu_slug_array($parent,'category',$pre_fix);
	}
	
	function get_slug($term_id = 0)
	{

		
		if(!$this->array_slug)
		{
			if(file_exists($this->file_cache))
			{

				$this->array_slug = include($this->file_cache);
			}
			else
			{
				$this->array_slug = $this->build_link_cache();
			}
		}
		if(isset($this->array_slug[$term_id]))
		return $this->array_slug[$term_id];
		return FALSE;
	}
	
	function build_link_cache($term_type=''){
		$this->load->helper('file');
		$cates = $this->select('term_id, term_parent,term_slug,term_name')->get_menu_slug_array(0,'/');
		$data_temp =array();
		$data = "<?php \n";
		$data.="return ";
		if($cates) {
			foreach($cates as $id =>$slug){
				if($slug == '') continue;
				$slug = rtrim($slug,'/');
				$data_temp[$id] = strtolower($slug);
			}
			$data_temp_txt = var_export($data_temp, true);
			$data.= $data_temp_txt;
			$data.="?>\n";
			write_file('./'.$this->file_cache, $data);
			return $data_temp;
		}
	}

	function get_menu($parent = 0, $type ='category')
	{
		return parent::get_menu($parent, 'category');
	}
}